home *** CD-ROM | disk | FTP | other *** search
- // generic JGNE init.c, by Kevin Irlen, Symantec Corp. 7/93
-
- /*
- Create a project of type Code Resource. Set Type to INIT, ID to 0, and check the "Locked"
- and "System Heap" attributes. Optionally, set Creator to RSED and File Type
- to rsrc so you can open this with ResEdit. Add this file and "Show INIT Icon.c".
-
- Add your JGNE 'CODE' resource, your icon resource(s), and any other needed resources
- to the built 'INIT' resource file.
- */
-
- /*
- We must overwrite the dummy instruction in the JGNE 'CODE' resource that
- does not "know" ahead of time whether it will have to branch to a previously loaded
- JGNE filter. Determining the location of the dummy instruction and overwriting it with
- the proper instruction works like this:
-
- At kBRAoffset will be the branch instruction leading to "main". The second word of that
- instruction is the number of bytes to branch over. From "main", it will be kLoadOffset
- bytes to the line which loads the address of the current JGNE filter if there is one, or
- writes a simple RTS (0x4E75) if there isn't.
- */
-
- #define rMyINITIcon -4094 // ID of icon to be shown at INIT time
- #define rMyJGNE 128 // ID of JGNE 'CODE' resource
-
- #define kBRAoffset 0x0018 // offset of bra to "main" in a standard header CODE resource
- #define kLoadOffset 0x0014 // offset in "main" of the line to be changed!
-
- Ptr JGNEFilterPtr : 0x29A; // low-memory global JGNEfilter
-
- OSErr ShowInitIcon(short icon_num,short move_x_by);
-
- main()
- {
- Handle myJGNE;
- Ptr branInstruction,loadInstruction;
- OSErr iErr;
-
- SetZone(SysZone);
-
- myJGNE = Get1Resource('CODE',rMyJGNE);
-
- if (myJGNE)
- {
- DetachResource(myJGNE);
-
- branInstruction = *myJGNE + kBRAoffset;
- loadInstruction = branInstruction + *((short *) (branInstruction + 2)) + kLoadOffset;
-
- if (JGNEFilterPtr) *((long *) (loadInstruction + 2)) = (long) JGNEFilterPtr;
- else *loadInstruction = 0x4E75;
-
- JGNEFilterPtr = *myJGNE;
- }
- else SysBeep(10);
-
- iErr = ShowInitIcon(rMyINITIcon,-1);
-
- if (iErr != noErr) SysBeep(10);
- }
-
-